<template>
  <div>
    <p>
      <span>用户名</span>
      <input type="text" placeholder="输入用户名" v-model="info.username" />
    </p>
    <p>
      <span>密码</span>
      <input type="text" placeholder="输入密码" v-model="info.password" />
    </p>
    <button @click="deng">登录</button>
  </div>
</template>

<script lang="ts" setup>
import { ref } from "vue";
import { login } from "../../api/api";
import { useRouter } from "vue-router";

const router = useRouter();

let info: any = ref({
  username: "",
  password: "",
});

async function deng() {
  let res = await login({
    username: info.value.username,
    password: info.value.password,
  });
  if (res.data.code === 200) {
    localStorage.setItem("token", res.data.token)
    router.push("/home");
  } else {
    alert("登陆失败");
  }
}
</script>

<style scoped>
</style>